package no.ntnu.fp.server;

import java.io.IOException;
import java.net.ConnectException;
import java.util.LinkedList;
import java.util.List;

import no.ntnu.fp.net.co.Connection;

public class ConnectionHandler implements MessageListener {
	
	private Connection connection;
	private Server server;
	
	private List<String> messages;
	
	public ConnectionHandler(Connection connection, Server server) {
		
		this.connection = connection;
		this.server = server;
		messages = new LinkedList<String>();
		
		new Thread(new MessageReceiver(connection, this)).start();
	}

	public void send(String data) {
		
		try {
			connection.send(data);
		} 
		catch (ConnectException e) {} 
		catch (IOException e) {}
	}

	public void messageReceived(String message) {
		
		messages.add(message);
		server.dataFromClient(message, this);
	}
}
